package gui;

import game.Bullet;
import game.GameBoard;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class GameView extends JPanel {
    
    private GameBoard game;
    
    public GameView(GameBoard game) {
	this.game = game;
    }
    
    public void paintComponent(final Graphics g) {
	super.paintComponent(g);
	Graphics2D g2d = (Graphics2D) g;
	setBackground(Color.DARK_GRAY);
	
	g2d.setColor(Color.cyan);
	g2d.fillOval(game.player.getX()-game.player.getCollisionRadius(), game.player.getY()-game.player.getCollisionRadius(), game.player.getCollisionRadius()*2, game.player.getCollisionRadius()*2);
	g2d.setColor(Color.RED);
	g2d.fillOval(game.enemy.getX()-game.enemy.getCollisionRadius(), game.enemy.getY()-game.enemy.getCollisionRadius(), game.enemy.getCollisionRadius()*2, game.enemy.getCollisionRadius()*2);

	if (game.showChainPenaltyRadius) {
	    g2d.setColor(Color.BLUE);
	    g2d.drawOval((int)(game.player.getX() - GameBoard.NEAR_MISS_RADIUS),(int)(game.player.getY() - GameBoard.NEAR_MISS_RADIUS),
		    (int)(GameBoard.NEAR_MISS_RADIUS*2),(int)(GameBoard.NEAR_MISS_RADIUS*2));
	}
	
	g2d.setColor(Color.MAGENTA);
	if (!game.enemyBullets.isEmpty()) {
        	for(Bullet b:game.enemyBullets){ 
        	    g2d.drawOval(b.getX()-Bullet.collisionRadius[b.size], b.getY() - Bullet.collisionRadius[b.size], 2*Bullet.collisionRadius[b.size], 2*Bullet.collisionRadius[b.size]);
        	    if (game.showChainPenaltyRadius) {
        		if (b.nearMiss){ 
        		    g2d.setColor(Color.RED);
        		} else {
        		    g2d.setColor(Color.GREEN);
        		}
        		g2d.drawOval(b.getX() - (int)GameBoard.BULLET_CHAIN_RADIUS, b.getY() - (int)GameBoard.BULLET_CHAIN_RADIUS, (int)GameBoard.BULLET_CHAIN_RADIUS*2, (int)GameBoard.BULLET_CHAIN_RADIUS*2);
        		g2d.setColor(Color.black);
        		g2d.drawOval(b.getX() - (int)GameBoard.BULLET_PENALTY_RADIUS, b.getY() - (int)GameBoard.BULLET_PENALTY_RADIUS, (int)GameBoard.BULLET_PENALTY_RADIUS*2, (int)GameBoard.BULLET_PENALTY_RADIUS*2);
        		g2d.setColor(Color.magenta);
        	    }
        	}
	}
	g2d.setColor(Color.green);
	if (!game.playerBullets.isEmpty()) {
        	for(Bullet b:game.playerBullets){ 
        	    g2d.drawOval(b.getX()-Bullet.collisionRadius[b.size], b.getY() - Bullet.collisionRadius[b.size], 2*Bullet.collisionRadius[b.size], 2*Bullet.collisionRadius[b.size]);
        	}
	}
	
    }
    
}
